package com.feel.easycloud.service.impl;

import com.feel.easycloud.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class EmailServiceImpl implements EmailService {

    @Autowired
    private JavaMailSender javaMailSender;

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    @Transactional
    public void sendEamil(String email,String code) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("490818417@qq.com");
        message.setTo("feelingjos@163.com");
        message.setSubject("EasyCloud 重置密码");
        message.setText("你好，您的验证码是" + code + "；");
        javaMailSender.send(message);
        redisTemplate.opsForValue().set(email+code,code);
    }
}
